<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>用户管理</title>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="keywords" content="" />
	<meta http-equiv="description" content="" />
	<link href="${ctx}/css/main.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/icon.css"/>
	<script type="text/javascript" src="${ctx}/js/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery.validate.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery.metadata.js"></script>
	<script type="text/javascript" src="${ctx}/js/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$('#sub').removeAttr('disabled');
			  
			$("tr.beover").mouseover(function() {
				$(this).addClass("over");
			}).mouseout(function() {
				$(this).removeClass("over");
			});
			
			$.validator.setDefaults({
				submitHandler: function(form) {
					$('#sub').attr('disabled','disabled');
					form.submit();
				},
				meta: "validate",
				ignoreTitle: true//解决与google Toolbar的冲突
			});
			$("#theform").validate({
				rules:{
					"username":{
							maxlength:64,
							minlength:1,
							rangelength:[1,64]
						},
					"name":{
							maxlength:64,
							minlength:1,
							rangelength:[1,64]
						}
				},
				success: function(label) {
					label.addClass("valid").html("<img src='${ctx}/images/ok.gif' border='0'/>")
				}
			});
            //修改用户信息时再次跳转到用户所在的页面的标识
            $("input[name='modFlag']").val(1);
		});
		
		function query(){
            var enabledValue = $("#enabledValue").val();
			$("#action").val("handle");
            $("#queryEnabledValue").val(enabledValue);
			$("#theform").submit();
		}
		
		function exportExcel(){
			$("#action").val("export");
			$("#theform").submit();
		}

        function update(id) {
            var enabledValue = $("#enabledValue").val();
            $("#queryEnabledValue").val(enabledValue);
            $("#action").val("input");
            $("#uid").val(id);
            $("#theform").submit();
        }

        function changePwd(id) {
            var enabledValue = $("#enabledValue").val();
            $("#queryEnabledValue").val(enabledValue);
            $("#action").val("changePwdInput");
            $("#uid").val(id);
            $("#theform").submit();
        }

        function dispatchRole(id) {
            var enabledValue = $("#enabledValue").val();
            $("#queryEnabledValue").val(enabledValue);
            $("#action").val("dispatchRole");
            $("#uid").val(id);
            $("#theform").submit();
        }

        function disableOtp(id) {
            $.ajax({
                type: 'POST',
                url: '${ctx}/user/user.do?action=disableOtp',
                data: {'user.id' : id},
                dataType: 'json',
                success: function(data){
                    if (data.flag == 0) {
                        alert("操作成功。");
                        $('#opt_' + id).hide();
                    }
                }
            });
        }
	</script>
  </head>
  <body>
  		<div>
  			<div class="titlediv">您所在的位置：用户管理->用户列表</div>
  			<div class="add_div_margin"><a href="${ctx}/user/user.do?action=input" class="easyui-linkbutton" iconCls="icon-add">添加用户</a></div>
  			<div>
  				<div>
  					<div class="pagediv">条件查询</div>
  					<div>
	  					<form id="theform" action="${ctx}/user/user.do" method="post" enctype="multipart/form-data">
	  					<input id="action" name="action" type="hidden" value="" />
                        <input id="page" name="page" type="hidden" value="${pageBean.page}"/>
                        <input id="uid" name="user.id" type="hidden" value="${user.id}" />
                        <input id="queryEnabledValue" name="queryEnabledValue" type="hidden" value="" />
				    	<table cellpadding="0" cellspacing="0" border="0" style="width:80%" class="querytab">
				    		<tr>
				    			<td>用户名:<input type="text" name="username" maxlength="16" value="${username}" /></td>
				    			<td>姓名:<input type="text" name="name" maxlength="16" value="${name}" /></td>
                                <td>是否有效:<s:select list="enabledStatusItems" listKey="value" listValue="name" name="enabledValue" id="enabledValue"/></td>
				    			<td>
				    				<input type="button" value="查询" onclick="query()"/>&nbsp;&nbsp;
				    				<input id="export" type="button" value="导出" onclick="exportExcel()"/>
				    			</td>
				    		</tr>
				    	</table>
				    	</form>
			    	</div>
  				</div>
  				<div>
  					<div class="pagediv">结果列表</div>
  					<div>
  					<table cellpadding="0" cellspacing="0" border="0" class="querytab">
			    		<tr class="font_bold">
			    			<td>序号</td>
			    			<td>编码</td>
			    			<td>用户名</td>
			    			<td>姓名</td>
			    			<td>手机</td>
			    			<td>电话</td>
			    			<td>邮件</td>
			    			<td>创建时间</td>
			    			<td>修改时间</td>
			    			<td>是否有效</td>
			    			<td>备注</td>
                            <td>角色</td>
			    			<td colspan="6">操作</td>
			    		</tr>
			    		<s:iterator value="users" status="index">
						<tr class="beover">
			    			<td>${index.count}</td>
			    			<td>${id}</td>
			    			<td><a href="${ctx}/user/user.do?action=view&user.id=${id}">${username}</a></td>
			    			<td>${name}</td>
			    			<td>${mobile}</td>
			    			<td>${tel}</td>
			    			<td>${email}</td>
			    			<td><s:date name="createdTime" format="yyyy-MM-dd HH:mm:ss" /></td>
			    			<td><s:date name="updatedTime" format="yyyy-MM-dd HH:mm:ss" /></td>
			    			<td>${enabled.name}</td>
			    			<td>${memo}</td>
                            <td>${roleName}</td>
                            <td>
                                <s:if test="otp.value == 1">
                                    <a id="opt_${id}" href="javascript:disableOtp('${id}');">关闭动态密码</a>
                                </s:if>
                            </td>
			    			<td><a href="javascript:update('${id}');">修改</a></td>
			    			<td><a href="javascript:changePwd('${id}');">更改密码</a></td>
			    			<td><a href="javascript:dispatchRole('${id}');">分配角色</a></td>
			    			<td><a href="${ctx}/user/user.do?action=dispatchApp&user.id=${id}">分配应用</a></td>
			    			<td><a href="${ctx}/user/user.do?action=del&user.id=${id}" onclick="return confirm('确实要删除吗？');">删除</a></td>
			    		</tr>
			    		</s:iterator>
			    	</table>
			    	</div>
			    	<div class="pagediv"><center>${pageString}</center></div>
  				</div>
  			</div>
  		</div>
  </body>
</html>
